﻿using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    ///  Type类型扩展方法类
    /// </summary>
    public static class TypeEx
    {
        /// <summary>
        /// 获取对象的基元类型
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>对象的基元类型</returns>
        public static PrimitiveDataTypes GetPrimitiveDataType(object obj)
        {
            if (obj == null)
            {
                return PrimitiveDataTypes.ReferenceType;
            }

            if (obj is bool)
            {
                return PrimitiveDataTypes.BoolType;
            }

            if (obj is char)
            {
                return PrimitiveDataTypes.CharType;
            }

            if (obj is byte)
            {
                return PrimitiveDataTypes.ByteType;
            }

            if (obj is sbyte)
            {
                return PrimitiveDataTypes.SByteType;
            }

            if (obj is Int16)
            {
                return PrimitiveDataTypes.Int16Type;
            }

            if (obj is UInt16)
            {
                return PrimitiveDataTypes.UInt16Type;
            }

            if (obj is Int32)
            {
                return PrimitiveDataTypes.Int32Type;
            }

            if (obj is UInt32)
            {
                return PrimitiveDataTypes.UInt32Type;
            }

            if (obj is Int64)
            {
                return PrimitiveDataTypes.Int64Type;
            }

            if (obj is UInt64)
            {
                return PrimitiveDataTypes.UInt64Type;
            }

            if (obj is Int128)
            {
                return PrimitiveDataTypes.Int128Type;
            }

            if (obj is UInt128)
            {
                return PrimitiveDataTypes.UInt128Type;
            }

            if (obj is BigInteger)
            {
                return PrimitiveDataTypes.BigIntegerType;
            }

            if (obj is float)
            {
                return PrimitiveDataTypes.FloatType;
            }

            if (obj is double)
            {
                return PrimitiveDataTypes.DoubleType;
            }

            if (obj is Half)
            {
                return PrimitiveDataTypes.HalfType;
            }

            if (obj is decimal)
            {
                return PrimitiveDataTypes.DecimalType;
            }

            if (obj is DateTime)
            {
                return PrimitiveDataTypes.DateTimeType;
            }

            if (obj is TimeSpan)
            {
                return PrimitiveDataTypes.TimeSpanType;
            }

            if (obj is DateTimeOffset)
            {
                return PrimitiveDataTypes.DateTimeOffsetType;
            }

            if (obj is TimeOnly)
            {
                return PrimitiveDataTypes.TimeOnlyType;
            }

            if (obj is DateOnly)
            {
                return PrimitiveDataTypes.DateOnlyType;
            }

            if (obj is Enum)
            {
                return PrimitiveDataTypes.EnumType;
            }

            if (obj is string)
            {
                return PrimitiveDataTypes.StringType;
            }

            if (obj is byte[])
            {
                return PrimitiveDataTypes.ByteAarrayType;
            }

            if (obj is short[])
            {
                return PrimitiveDataTypes.ShortAarrayType;
            }

            if (obj is float[])
            {
                return PrimitiveDataTypes.FloatAarrayType;
            }

            if (obj is int[])
            {
                return PrimitiveDataTypes.Int32AarrayType;
            }

            if (obj is double[])
            {
                return PrimitiveDataTypes.DoubleAarrayType;
            }

            return PrimitiveDataTypes.ReferenceType;
        }

    }

}
